const { DataTypes } = require('sequelize')
const seq = require('../db/seq')
const Goods = require('../model/good.model')
const User = require('../model/user.model')
const Cart = seq.define('zd_cart', {
    goods_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '物品ID'
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '用户ID'
    },
    number: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '商品数量',
        defaultValue: 1
    },
    selected: {
        type: DataTypes.BOOLEAN,
        allowNull: true,
        comment: '是否选中',
        defaultValue: true
    },
})
// // 同步（建表）
// Cart.sync({ force: true })
// // // 外联表格
//  Cart.belongsTo(User, { foreignKey: 'user_id', targetKey: 'id'})
Cart.belongsTo(Goods, { foreignKey: 'goods_id', as: 'goods_info' })
module.exports = Cart